import http from "@/utils/http"

const baseUrl = "/oss"

export interface OssFileVo {
    value: any
    ossId: string,
    fileType: string,
    clientUrl: string
}

export interface FileStatus {
    currentIndex: number,
    total: number,
    nextIndex: number,
    hash: string,
}

/**
 * 上传小文件
 * @param file:FormData.file
 * @param file:FormData.userId
 * @param file:FormData.subject
 * @return OssFileVo
 */
export function uploadSmall(file: FormData) {
    return http.post(`${baseUrl}/upload`, file)
}


/**
 * 上传大文件
 * @param file:FormData.file
 * @param file:FormData.hash
 * @param file:FormData.chunkHash
 * @param file:FormData.userId
 * @param file:FormData.subject
 * @param file:FormData.index
 * @param file:FormData.fileName
 * @return OssFileVo
 *
 * @apiNote
 * 当chunkHash为end时开始合并
 */
export function uploadLarge(file: FormData) {
    return http.post(`${baseUrl}/upload/large`, file)
}


/**
 * 获取文件上传状态
 */
export function getUploadStatus(hash: string, userId: string) {
    return http.get(`${baseUrl}/status?hash=${hash}&userId=${userId}`)
}